<template>
  <!-- 打印行为监控 -->
  <div>
    <div slot="header" class="clearfix">
      <span style="float: left; padding: 3px 0">打印行为监控策略列表</span>
      <div class="btn-right">
        <el-button type="text" icon="el-icon-plus" @click="openDialog('add','')" v-if="addFlag">新增</el-button>
        <el-button type="text" icon="el-icon-refresh">刷新</el-button>
      </div>
    </div>
    <com-table :tableData="tableData" url="app" keyName="app" :has-data="hasData" :table-head-list="tableHeadList"
      :total-count="totalCount" :page-num="pageNum" :page-size="pageSize" :page-sizes="pageSizes"
      :table-loading="loading" :table-height="tableHeight" :is-show-select="false" :page-show="false"
      :handle-show="true" :merge-flag="false" :baddtsd="false" @setSearchHeight="setTableHeight"
      @openDialog="openDialog" ref="comTable" :ifShowOnline="true" addOnline="状态" @isOnline="isOnline">
      <template slot="handle" slot-scope="scope">
        <el-button type="text" size="small" @click="openDialog('update',scope.row)" icon="el-icon-edit">修改
        </el-button>
        <!-- <el-button type="text" icon="el-icon-delete" style="color:#F56C6C">删除
        </el-button> -->
      </template>
    </com-table>
  </div>
</template>

<script>
import ComTable from "../../components/table/comTable";
export default {
  name: "printingBehavior",
  data() {
    return {
      pageNum: 1,
      pageSize: 10,
      pageSizes: [5, 10, 20, 100],
      totalCount: 0,
      tableData: [], // 表格数据
      tableHeight: "", // 表格高度
      hasData: true,
      loading: false, // 数据加载状态遮罩
      checkList: [],
      tableHeadList: [
        { columnComment: "策略名称", columnName: "name", },
        // { columnComment: "状态", columnName: "state", typeCollection: "stateEnum",},
        { columnComment: "创建人", columnName: "creator", },
        { columnComment: "产生时间", columnName: "enableTime", },

      ],
      dialogControl: false,
      addFlag: true
    };
  },
  components: {
    ComTable,
  },
  created() {
    this.setTableHeight()
    this.getTableData()
  },
  methods: {
    getTableData() {
      this.$get('sjrz/policy/print').then(res => {
        let { data } = res.data
        this.tableData = data
        if (this.tableData.length > 0) {
          this.addFlag = false;
        }
      })
    },
    //新建与修改
    openDialog(type, row) {
      if (type == 'update') {
        this.$router.push({
          path: '/dataSecurityForm',
          name: 'dataSecurityForm',
          params: {
            formName: 'printingBehavior',
            type: type,
            row
          }
        });
      }
      this.$router.push({
        path: '/dataSecurityForm',
        name: 'dataSecurityForm',
        params: {
          formName: 'printingBehavior',
          type: type,
        }
      });
    },
    dialogClosed() { },
    addTerminal() {
      this.dialogControl = false;
      this.$message({
        type: "success",
        message: "新增成功！",
      });
    },
    modifyTerminal() {
      this.dialogControl = false;
      this.$message({
        type: "success",
        message: "修改成功！",
      });
    },
    delegods() {
      this.$confirm("确认删除？", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功！",
          });
        })
        .catch((_) => { });
    },
    setTableHeight() {
      let clientHeiht =
        window.innerHeight || document.documentElement.clientHeight;
      this.tableHeight = clientHeiht - 160;
    },
    isOnline(val, row) {
      let params = {
        Root: {
          Policy: row.Root.Policy,
        },
        creator: sessionStorage.getItem('userName'),
        enableTime: "",
        name: row.Root.Policy.name,
        state: val,
      }
      this.$postForJson('sjrz/policy/print', { policy: params }).then(res => {
        let { data } = res
        if (data.errorcode == '0') {
          this.$message({
            type: "success",
            message: "提交成功！",
          });
          this.getTableData()
        }
      })
    }
  },
};
</script>

<style scoped>
.el-checkbox-group {
  display: flex;
  flex-direction: column;
}
.el-select {
  width: 100%;
}
.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}
.btn-right {
  display: inline-block;
  float: right;
}
</style>